home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 / Ham Radio 2000.iso / ham2000 / packet / tf27bsrc / cruntime.mac < prev    next >
Text File  |  1994-07-04  |  60KB  |  1,478 lines

  1. ; ***********************************************************************
  2. ; *                                                                     *
  3. ; *                                                                     *
  4. ; *    *****                      *****                                 *
  5. ; *      *****                  *****                                   *
  6. ; *        *****              *****                                     *
  7. ; *          *****          *****                                       *
  8. ; *            *****      *****                                         *
  9. ; *              *****  *****                                           *
  10. ; *            *****      *****                                         *
  11. ; *          *****          *****          The Firmware. The Net.       *
  12. ; *        *****              *****        Portable. Compatible.        *
  13. ; *      *****                  *****      Public Domain.               *
  14. ; *    *****                      *****    By NORD><LINK.               *
  15. ; *                                                                     *
  16. ; *                                                                     *
  17. ; *                                                                     *
  18. ; *    CRUNTIME.MAC   -     Z80 C Runtime Library                       *
  19. ; *                         (modifizierte Version des Runtime-Moduls    *
  20. ; *                         aus dem Q/C-Compilerpaket)                  *
  21. ; *                                                                     *
  22. ; *                                                                     *
  23. ; *    angelegt:      DC4OX                                             *
  24. ; *    modifiziert:                                                     *
  25. ; *                                                                     *
  26. ; ***********************************************************************
  27.  
  28.  
  29.     .z80
  30.  
  31.  
  32. ; =======================================================================
  33. ;
  34. ;   Namen mit '?' als erstem Zeichen sind die Namen, die der Compiler
  35. ;   benutzt. Sonstige Namen sind als Aequivalenzen zu den ?-Namen zur
  36. ;   vereinfachten Bearbeitung des vom Compiler stammenden Assembler-
  37. ;   Sources vorgesehen.
  38. ;
  39. ;   Fuer die Aufrufe mit Parametern siehe auch MAKROS.MAC.
  40. ;
  41. ;
  42. ; * (RST38)   ?loc     local   Parameter hinter Aufruf (8 Bit) :
  43. ;
  44. ;                                00offset   LD HL,(BC+offset)
  45. ;                                01offset   LD (BC+offset),HL
  46. ;                                10offset   LD (BC+offset),0000h  Word
  47. ;                                11offset   LD (BC+offset),00h    Byte
  48. ;
  49. ;
  50. ; * (RST30)   ?addhl   addhl      HL := HL + 8-Bit-Parameter (hinter Aufruf)
  51. ; *           ?Aeq0    Aeq0       HL := (A == 0)
  52. ;             ?gcf     lHiBx      HL := LSB (BC)   sign extension
  53. ;             ?gc      lHiHx      HL := LSB (HL)   sign extension
  54. ;   (RST10)   ?sxt     lHAx       HL := A          sign extension
  55. ; *           ?gcsi    lDiiHx     DE := LSB ((HL)) sign extension
  56. ;             ?gcs     lDiHx      DE := LSB (HL)   sign extension
  57. ;   (RST18)   ?gf      lHiB       HL := (BC)
  58. ;   (RST20)   ?g       lHiH       HL := (HL)
  59. ;             ?gs      lDiH       DE := (HL)
  60. ; * (RST08)   ?inc     incwiH   (HL) := (HL) + 1, 16 Bit, HL := HL + 1
  61. ; *           ?dec     decwiH   (HL) := (HL) - 1, 16 Bit, HL := HL - 1
  62. ;             ?p       liDH     (DE) := HL
  63. ;             ?so      DorH       HL := DE  | HL
  64. ;             ?sx      DxorH      HL := DE  ^ HL
  65. ;             ?sa      DandH      HL := DE  & HL
  66. ; *           ?sec     DeqAx      HL := DE == A  sign extended
  67. ;             ?se      DeqH       HL := DE == HL
  68. ;             ?sne     DneH       HL := DE != HL
  69. ;             ?sgt     DgtHs      HL := DE  > HL signed
  70. ;             ?ugt     DgtHu      HL := DE  > HL unsigned
  71. ;             ?slt     DltHs      HL := DE  < HL signed
  72. ;             ?ult     DltHu      HL := DE  < HL unsigned
  73. ;             ?sle     DleHs      HL := DE <= HL signed
  74. ;             ?ule     DleHu      HL := DE <= HL unsigned
  75. ;             ?sge     DgeHs      HL := DE >= HL signed
  76. ;             ?uge     DgeHu      HL := DE >= HL unsigned
  77. ;             ?ssr     DsrHa      HL := DE >> HL arithmetic
  78. ;             ?s1sr    HsrDa      HL := HL >> DE arithmetic
  79. ;             ?ssl     DslH       HL := DE << HL
  80. ;             ?s1sl    HslD       HL := HL << DE
  81. ;             ?usr     DsrHl      HL := DE >> HL logic
  82. ;             ?u1sr    HsrDl      HL := HL >> DE logic
  83. ;             ?ss      DminH      HL := DE - HL
  84. ;             ?s1s     HminD      HL := HL - DE
  85. ;             ?sneg    com2H      HL := -HL
  86. ;             ?scom    com1H      HL := ~HL
  87. ;             ?sna     nDandH     HL := !(DE & HL)
  88. ;   (RST28)   ?sn      nH         HL := !HL
  89. ;             ?smult   DmulH      HL := DE * HL
  90. ;             ?umult     "           "
  91. ;             ?sdiv    DdivHs     HL := DE / HL, signed
  92. ;             ?s1div   HdivDs     HL := HL / DE, signed
  93. ;             ?udiv    DdivHu     HL := DE / HL, unsigned
  94. ;             ?u1div   HdivDu     HL := HL / DE, unsigned
  95. ;             ?srem    DmodHs     HL := DE % HL, signed
  96. ;             ?s1rem   HmodDs     HL := HL % DE, signed
  97. ;             ?urem    DmodHu     HL := DE % HL, unsigned
  98. ;             ?u1rem   HmodDu     HL := HL % DE, unsigned
  99. ;
  100. ;             ?sw      switch   switch-Anwahl, HL enthaelt zu testenden
  101. ;                               Wert, Tabelle als Parameter hinter
  102. ;                               Aufruf :
  103. ;                                16 Bit Anzahl Faelle ohne default
  104. ;                                je Fall :  16 Bit Fall-Wert
  105. ;                                           16 Bit Adresse des Falls
  106. ;                                           .
  107. ;                                           .
  108. ;                                16 Bit Adresse default Bearbeitung
  109. ;             ?en      fentp    function entry for parameter,
  110. ;                               es werden die Stackframepointer
  111. ;                               (BC/IX) gesetzt, so dass auf
  112. ;                               Funktionsargumente zugegriffen werden kann
  113. ;             ?ens     fentpl   function entry for parameter/locals,
  114. ;                               wie fentp, zusaetzlich wird Platz fuer
  115. ;                               lokale Variable auf dem Stack
  116. ;                               geschaffen, Platz in Bytes negativ als
  117. ;                               Parameter hinter Aufruf (16 Bit)
  118. ;
  119. ;             ?exs     fextpl   function exit for parameter/locals,
  120. ;                               nach fentpl, der lokal benoetigte
  121. ;                               Platz wird zurueckgegeben, Platz in
  122. ;                               Bytes positiv als Parameter hinter
  123. ;                               Aufruf (16 Bit)
  124. ;
  125. ;
  126. ; * -> zusaetzlich zum originalen Runtime-Modul
  127. ;
  128. ;
  129. ;   Zeichenerklaerung ?-Namen :
  130. ;
  131. ;    s am Namensanfang steht fuer "short" in Unterscheidung zu der
  132. ;    long-Library
  133. ;
  134. ;    u am Namensanfang steht fuer den unsigned-Typ
  135. ;
  136. ;    g  = get                 HL primary register
  137. ;    gs = get secondary       DE secondary register
  138. ;    gc = get character       BC stack frame pointer
  139. ;    gf = get from frame
  140. ;    p  = put
  141. ;
  142. ;
  143. ;   Zeichenerklaerung Aequivalente :
  144. ;
  145. ;      B = BC                             or = logisches Oder
  146. ;      D = DE                            xor = logisches Exklusiv-Oder
  147. ;      H = HL                            and = logisches Und
  148. ;      A = A                              eq = equal, ==
  149. ;      l = load (1. Zeichen)              ne = not equal, !=
  150. ;          logic sonst                    gt = greater than, >
  151. ;      u = unsigned                       lt = less than, <
  152. ;      s = signed                         le = less equal, <=
  153. ;      a = arithmetic                     ge = greater equal, >=
  154. ;      x = sign extend, Byte -> Word      sr = shift right, >>
  155. ;      i = indirect (reg)                 sl = shift left, <<
  156. ;   incw = increment word, ++            min = minus, -
  157. ;   decw = decrement word, --           com1 = Einerkomplement, ~
  158. ;      n = not, !                       com2 = Zweierkomplement, -
  159. ;                                        mul = multiply, *
  160. ;                                        div = divide, /
  161. ;                                        mod = modulo, %
  162. ;
  163. ; =======================================================================
  164.  
  165.  
  166.  
  167.  
  168.  
  169. ; +---------------------------------------------------------------------+
  170. ; |                                                                     |
  171. ; | (RST38) Zugriffe auf Funktionsparameter und lokale Variable sowie   |
  172. ; | Loeschen lokaler Variable.                                          |
  173. ; |                                                                     |
  174. ; | 8-Bit-Parameter hinter Aufruf :                                     |
  175. ; |                                                                     |
  176. ; |   00offset  -  LD HL,(BC+offset)              offset maximal 64 !   |
  177. ; |   01offset  -  LD (BC+offset),HL                                    |
  178. ; |   10offset  -  LD (BC+offset),0000h Word                            |
  179. ; |   11offset  -  LD (BC+offset),00h   Byte                            |
  180. ; |                                                                     |
  181. ; | A benutzt.                                                          |
  182. ; |                                                                     |
  183. ; +---------------------------------------------------------------------+
  184.  
  185.           public local
  186.           public ?loc
  187.  
  188. local:
  189. ?loc:     ex    (SP),HL         ; 8-Bit-Parameter vom Stack holen
  190.           ld    A,(HL)
  191.           inc   HL              ; Returnadresse ein Byte weiter
  192.           ex    (SP),HL
  193.  
  194.           bit   7,A             ; 1xxxxxxx ?
  195.           jr    NZ,?loc2        ; ja   -
  196.           bit   6,A             ; nein - 01xxxxxx ?
  197.           jr    NZ,?loc1        ; ja   -
  198.  
  199. ;
  200. ; 00xxxxxx :  LD HL,(BC+xxxxxx)
  201. ;
  202.           ld    L,A             ; nein - HL = Offset
  203.           ld    H,0           
  204.           add   HL,BC           ;             + BC
  205.           ld    A,(HL)          ; LSB holen
  206.           inc   HL              ; Zeiger auf MSB
  207.           ld    H,(HL)          ; MSB holen
  208.           ld    L,A             ; HL = MSBLSB
  209.           ret                   ; das war's
  210.  
  211. ;
  212. ; 01xxxxxx :  LD (BC+xxxxxx),HL
  213. ;
  214. ?loc1:    push  DE              ; benutztes Register sichern
  215.           ex    DE,HL           ; HL merken
  216.           and   00111111b       ; Offset maskieren
  217.           ld    L,A             ; HL = Offset
  218.           ld    H,0
  219.           add   HL,BC           ;      + BC
  220.           ld    (HL),E          ; LSB schreiben
  221.           inc   HL              ; Zeiger auf MSB-Stelle
  222.           ld    (HL),D          ; MSB schreiben
  223.           ex    DE,HL           ; HL restaurieren
  224.           pop   DE              ; benutztes Register restaurieren
  225.           ret                   ; das war's
  226.  
  227. ?loc2:    bit   6,A             ; 11xxxxxx ?
  228.           jr    NZ,?loc3        ; ja   -
  229.  
  230. ;
  231. ; 10xxxxxx :  LD (BC+xxxxxx),0000h
  232. ;
  233.           push  HL              ; nein - benutztes Register sichern
  234.           and   00111111b       ; Offset maskieren
  235.           ld    L,A             ; HL = Offset
  236.           ld    H,0
  237.           add   HL,BC           ;      + BC
  238.           ld    (HL),00h        ; LSB loeschen
  239.           inc   HL              ; Zeiger auf MSB-Stelle
  240.           ld    (HL),00h        ; MSB loeschen
  241.           pop   HL              ; benutztes Register restaurieren
  242.           ret                   ; das war's
  243.  
  244. ;
  245. ; 11xxxxxx :  LD (BC+xxxxxx),00h
  246. ;
  247. ?loc3:    push  HL              ; benutztes Register sichern
  248.           and   00111111b       ; Offset maskieren
  249.           ld    L,A             ; HL = Offset
  250.           ld    H,0
  251.           add   HL,BC           ;      + BC
  252.           ld    (HL),00h        ; Byte loeschen
  253.           pop   HL              ; benutztes Register restaurieren
  254.           ret                   ; das war's
  255.  
  256.  
  257.  
  258.  
  259.  
  260. ; +---------------------------------------------------------------------+
  261. ; |                                                                     |
  262. ; | (RST30) Offset auf HL addieren, 8-Bit-Offset hinter Aufruf.         |
  263. ; |                                                                     |
  264. ; | DE benutzt.                                                         |
  265. ; |                                                                     |
  266. ; +---------------------------------------------------------------------+
  267.  
  268.           public addhl
  269.           public ?addhl
  270.  
  271. addhl:
  272. ?addhl:   ex    (SP),HL         ; 8-Bit-Parameter vom Stack holen, HL sichern
  273.           ld    E,(HL)
  274.           ld    D,0
  275.           inc   HL              ; Returnadresse ein Byte weiter
  276.           ex    (SP),HL         ; Returnaddresse auf Stack, HL wieder setzen
  277.           add   HL,DE           ; Offset addieren
  278.           ret                   ; das war's
  279.  
  280.  
  281.  
  282.  
  283.  
  284. ; +--------------------------------------------------------------------+
  285. ; |                                                                    |
  286. ; | Teste A auf 0.                                                     |
  287. ; |                                                                    |
  288. ; | A == 0  ->  HL = 1 (TRUE)                                          |
  289. ; | A != 0  ->  HL = 0 (FALSE)                                         |
  290. ; |                                                                    |
  291. ; | A benutzt.                                                         |
  292. ; |                                                                    |
  293. ; +--------------------------------------------------------------------+
  294.  
  295.           public Aeq0
  296.           public ?Aeq0
  297.  
  298. Aeq0:
  299. ?Aeq0:    or    A               ; A == 0 ?
  300.           jr    Z,?Aeq0a        ; ja   - HL = TRUE  (1)
  301.           xor   A               ; nein - HL = FALSE (0)
  302.           jr    ?Aeq0b
  303. ?Aeq0a:   inc   A
  304. ?Aeq0b:   ld    L,A
  305.           ld    H,0
  306.           ret                   ; das war's
  307.  
  308.  
  309.  
  310.  
  311.  
  312. ; +---------------------------------------------------------------------+
  313. ; |                                                                     |
  314. ; | HL indirekt Laden mit Byte an BC, Sign Extension HL := LSB (BC)     |
  315. ; |                                                                     |
  316. ; | A benutzt.                                                          |
  317. ; |                                                                     |
  318. ; +---------------------------------------------------------------------+
  319.  
  320.           public lHiBx
  321.           public ?gcf
  322.  
  323. lHiBx:
  324. ?gcf:     ld    L,C             ; fuer HL = LSB (HL) sign extension, s.u.
  325.           ld    H,B
  326.  
  327.  
  328.  
  329.  
  330.  
  331. ; +---------------------------------------------------------------------+
  332. ; |                                                                     |
  333. ; | HL indirekt laden mit Byte an (HL), Sign extension,                 |
  334. ; | HL := LSB (HL).                                                     |
  335. ; |                                                                     |
  336. ; | A benutzt.                                                          |
  337. ; |                                                                     |
  338. ; +---------------------------------------------------------------------+
  339.  
  340.           public lHiHx
  341.           public ?gc
  342.  
  343. lHiHx:
  344. ?gc:      LD    A,(HL)          ; fuer HL := A sign extension, s.u.
  345.  
  346.  
  347.  
  348.  
  349.  
  350. ; +---------------------------------------------------------------------+
  351. ; |                                                                     |
  352. ; | (RST10) HL laden mit A, Sign Extension.                             |
  353. ; |                                                                     |
  354. ; | A benutzt.                                                          |
  355. ; |                                                                     |
  356. ; +---------------------------------------------------------------------+
  357.  
  358.           public lHAx
  359.           public ?sxt
  360.  
  361. lHAx:
  362. ?sxt:     ld    L,A             ; LSB setzen
  363.           rlca                  ; Bit 8 = Vorzeichen = Carry
  364.           sbc   A,A             ; A - A - Carry -> FF wenn negativ, sonst 0
  365.           ld    H,A             ; MSB setzen
  366.           ret                   ; das war's
  367.  
  368.  
  369.  
  370.  
  371.  
  372. ; +---------------------------------------------------------------------+
  373. ; |                                                                     |
  374. ; | DE laden mit Byte an Adresse an (HL), Sign Extension.               |
  375. ; |                                                                     |
  376. ; | A benutzt.                                                          |
  377. ; |                                                                     |
  378. ; +---------------------------------------------------------------------+
  379.  
  380.           public lDiiHx
  381.           public ?gcsi
  382.  
  383. lDiiHx:
  384. ?gcsi:    call  ?g              ; Adresse an (HL) fuer ?gcs (s.u.) holen
  385.  
  386.  
  387.  
  388.  
  389.  
  390. ; +---------------------------------------------------------------------+
  391. ; |                                                                     |
  392. ; | DE laden mit Byte an (HL), Sign Extension.                          |
  393. ; |                                                                     |
  394. ; | A benutzt.                                                          |
  395. ; |                                                                     |
  396. ; +---------------------------------------------------------------------+
  397.  
  398.           public lDiHx
  399.           public ?gcs
  400.  
  401. lDiHx:
  402. ?gcs:     ld    A,(HL)          ; Byte an HL holen
  403.           ld    E,A             ; LSB setzen
  404.           rlca                  ; Bit 8 = Vorzeichen = Carry
  405.           sbc   A,A             ; A - A - Carry -> FF wenn negativ, sonst 0
  406.           ld    D,A             ; MSB setzen
  407.           ret                   ; das war's
  408.  
  409.  
  410.  
  411.  
  412.  
  413. ; +---------------------------------------------------------------------+
  414. ; |                                                                     |
  415. ; | (RST18) HL laden mit 16-Bit-Wort an (BC).                           |
  416. ; |                                                                     |
  417. ; | A benutzt.                                                          |
  418. ; |                                                                     |
  419. ; +---------------------------------------------------------------------+
  420.  
  421.           public lHiB
  422.           public ?gf
  423.  
  424. lHiB:
  425. ?gf:      ld    L,C             ; HL := BC fuer ?g (s.u.)
  426.           ld    H,B
  427.  
  428.  
  429.  
  430.  
  431.  
  432. ; +---------------------------------------------------------------------+
  433. ; |                                                                     |
  434. ; | (RST20) HL laden mit 16-Bit-Wort an (HL).                           |
  435. ; |                                                                     |
  436. ; | A benutzt.                                                          |
  437. ; |                                                                     |
  438. ; +---------------------------------------------------------------------+
  439.  
  440.           public lHiH
  441.           public ?g
  442.  
  443. lHiH: 
  444. ?g:       ld    A,(HL)          ; LSB holen
  445.           inc   HL              ; Zeiger auf MSB
  446.           ld    H,(HL)          ; MSB holen
  447.           ld    L,A             ; LSB setzen
  448.           ret                   ; das war's
  449.  
  450.  
  451.  
  452.  
  453.  
  454. ; +---------------------------------------------------------------------+
  455. ; |                                                                     |
  456. ; | DE laden mit 16-Bit-Wort an (HL), HL := HL + 1.                     |
  457. ; |                                                                     |
  458. ; +---------------------------------------------------------------------+
  459.  
  460.           public lDiH
  461.           public ?gs
  462.  
  463. lDiH:
  464. ?gs:      ld    E,(HL)          ; LSB holen
  465.           inc   HL              ; Zeiger auf MSB
  466.           ld    D,(HL)          ; MSB holen
  467.           ret                   ; das war's
  468.  
  469.  
  470.  
  471.  
  472.  
  473. ; +---------------------------------------------------------------------+
  474. ; |                                                                     |
  475. ; | (RST08) 16-Bit-Wort an (HL) um 1 erhoehen, HL := HL + 1.            |
  476. ; |                                                                     |
  477. ; | A, DE benuzt.                                                       |
  478. ; |                                                                     |
  479. ; +---------------------------------------------------------------------+
  480.  
  481.           public incwiH
  482.           public ?inc
  483.  
  484. incwiH: 
  485. ?inc:     push  HL              ; Adresse sichern
  486.           call  ?g              ; LD HL,(HL) - Inhalt holen
  487.           inc   HL              ; + 1
  488.           pop   DE              ; Adresse holen
  489.           jr    ?p              ; LD (DE),HL - Inhalt zurueck
  490.  
  491.  
  492.  
  493.  
  494.  
  495. ; +---------------------------------------------------------------------+
  496. ; |                                                                     |
  497. ; | 16-Bit-Wort an (HL) um 1 erniedrigen, HL := HL - 1.                 |
  498. ; |                                                                     |
  499. ; | A, DE benutzt.                                                      |
  500. ; |                                                                     |
  501. ; +---------------------------------------------------------------------+
  502.  
  503.           public decwiH
  504.           public ?dec
  505.  
  506. decwiH: 
  507. ?dec:     push  HL              ; Adresse sichern
  508.           call  ?g              ; LD HL,(HL) - Inhalt holen
  509.           dec   HL              ; - 1
  510.           pop   DE              ; Adresse holen - dann ?p (s.u.)
  511.  
  512.  
  513.  
  514.  
  515.  
  516. ; +---------------------------------------------------------------------+
  517. ; |                                                                     |
  518. ; | Inhalt von HL an (DE) schreiben, DE := DE + 1.                      |
  519. ; |                                                                     |
  520. ; | A benutzt.                                                          |
  521. ; |                                                                     |
  522. ; +---------------------------------------------------------------------+
  523.  
  524.           public liDH
  525.           public ?p
  526.  
  527. liDH:   
  528. ?p:       ld    A,L             ; LSB laden
  529.           ld    (DE),A          ; LSB schreiben
  530.           inc   DE              ; Zeiger auf MSB
  531.           ld    A,H             ; MSB laden
  532.           ld    (DE),A          ; MSB schreiben
  533.           ret                   ; das war's
  534.  
  535.  
  536.  
  537.  
  538.  
  539. ; +---------------------------------------------------------------------+
  540. ; |                                                                     |
  541. ; | HL mit DE Oder-verknuepfen, HL := HL | DE.                          |
  542. ; |                                                                     |
  543. ; | A benutzt.                                                          |
  544. ; |                                                                     |
  545. ; +---------------------------------------------------------------------+
  546.  
  547.           public DorH
  548.           public ?so
  549.  
  550. DorH:
  551. ?so:      ld    A,L             ; LSB ...
  552.           or    E
  553.           ld    L,A
  554.           ld    A,H             ; MSB ...
  555.           or    D
  556.           ld    H,A
  557.           ret                   ; das war's
  558.  
  559.  
  560.  
  561.  
  562.  
  563. ; +---------------------------------------------------------------------+
  564. ; |                                                                     |
  565. ; | HL mit DE Exklusiv-Oder verknuepfen, HL := HL ^ DE.                 |
  566. ; |                                                                     |
  567. ; | A benutzt.                                                          |
  568. ; |                                                                     |
  569. ; +---------------------------------------------------------------------+
  570.  
  571.           public DxorH
  572.           public ?sx
  573.  
  574. DxorH:   
  575. ?sx:      ld    A,L             ; LSB ...
  576.           xor   E
  577.           ld    L,A
  578.           ld    A,H             ; MSB ...
  579.           xor   D
  580.           ld    H,A
  581.           ret                   ; das war's
  582.  
  583.  
  584.  
  585.  
  586.  
  587. ; +---------------------------------------------------------------------+
  588. ; |                                                                     |
  589. ; | HL mit DE Und-verknuepfen, HL := HL & DE.                           |
  590. ; |                                                                     |
  591. ; | A benutzt.                                                          |
  592. ; |                                                                     |
  593. ; +---------------------------------------------------------------------+
  594.  
  595.           public DandH
  596.           public ?sa
  597.  
  598. DandH:
  599. ?sa:      ld    A,L             ; LSB ...
  600.           and   E
  601.           ld    L,A
  602.           ld    A,H             ; MSB ...
  603.           and   D
  604.           ld    H,A
  605.           ret                   ; das war's
  606.  
  607.  
  608.  
  609.  
  610.  
  611. ;
  612. ; Alle der folgenden Vergleichs-Routinen geben zurueck : 
  613. ;
  614. ;   wenn Bedingung wahr   = TRUE   dann HL = 1 und Z-Flag ist geloescht
  615. ;   wenn Bedingung falsch = FALSE  dann HL = 0 und Z-Flag ist gesetzt
  616. ;
  617. ; Fuer einen vorzeichenbehafteten Vergleich werden die positiven und
  618. ; negativen Zahlen zunaechst so in vorzeichenlose Zahlen gewandelt, dass
  619. ; ein vorzeichenloser Vergleich dann das richtige Resultat ergibt.
  620. ; Dies Umwandeln geschieht durch Exklusiv-Oder des Vorzeichenbits mit 1 :
  621. ;
  622. ;       -32768 (0x8000) --> 0     (0x0000)
  623. ;       -32767 (0x8001) --> 1     (0x0001)
  624. ;        .....
  625. ;           -1 (0xFFFF) --> 32767 (0x7FFF)
  626. ;            0 (0x0000) --> 32768 (0x8000)
  627. ;            1 (0x0001) --> 32769 (0x8001)
  628. ;        .....
  629. ;        32766 (0x7FFE) --> 65534 (0xFFFE)
  630. ;        32767 (0x7FFF) --> 65535 (0xFFFF)
  631. ;
  632.  
  633.  
  634.  
  635.  
  636.  
  637. ; +---------------------------------------------------------------------+
  638. ; |                                                                     |
  639. ; | DE mit A (sign extended) vergleichen, HL := DE == A sign extended.  |
  640. ; |                                                                     |
  641. ; | TRUE -> HL=1, Z=0   FALSE -> HL=0, Z=1                              |
  642. ; |                                                                     |
  643. ; | A benutzt.                                                          |
  644. ; |                                                                     |
  645. ; +---------------------------------------------------------------------+
  646.  
  647.           public DeqAx 
  648.           public ?sec
  649.  
  650. DeqAx:
  651. ?sec:     call  ?sxt            ; HL = A sign extended fuer ?se (s.u.)
  652.  
  653.  
  654.  
  655.  
  656.  
  657. ; +---------------------------------------------------------------------+
  658. ; |                                                                     |
  659. ; | HL mit DE vergleichen, HL := HL == DE.                              |
  660. ; |                                                                     |
  661. ; | TRUE -> HL=1, Z=0   FALSE -> HL=0, Z=1                              |
  662. ; |                                                                     |
  663. ; | A benutzt.                                                          |
  664. ; |                                                                     |
  665. ; +---------------------------------------------------------------------+
  666.  
  667.           public DeqH
  668.           public ?se
  669.  
  670. DeqH:
  671. ?se:      xor   A               ; Carry fuer Subtraktion loeschen
  672.           sbc   HL,DE           ; HL := HL - DE
  673.           jr    Z,?true         ; gleich, dann TRUE zurueckgeben
  674.           ld    H,A             ; sonst HL = 0, Z = 0, FALSE setzen
  675.           ld    L,A
  676.           xor   A
  677.           ret                   ; das war's
  678.  
  679.  
  680.  
  681.  
  682.  
  683. ; +---------------------------------------------------------------------+
  684. ; |                                                                     |
  685. ; | Ungleich Vergleich, HL := DE != HL.                                 |
  686. ; |                                                                     |
  687. ; | TRUE -> HL=1, Z=0   FALSE -> HL=0, Z=1                              |
  688. ; |                                                                     |
  689. ; | A, DE benutzt.                                                      |
  690. ; |                                                                     |
  691. ; +---------------------------------------------------------------------+
  692.  
  693.           public DneH
  694.           public ?sne
  695.  
  696. DneH:
  697. ?sne:     xor   A               ; Carry fuer Subtraktion loeschen
  698.           sbc   HL,DE           ; HL := HL - DE
  699.           ret   Z               ; gleich, dann war's das, HL := A := 0
  700.           ld    H,A             ; sonst HL := 1, d.h. TRUE
  701.           ld    L,A
  702. ?true:    inc   L               ; das war's
  703.           ret
  704.  
  705.  
  706.  
  707.  
  708.  
  709. ; +---------------------------------------------------------------------+
  710. ; |                                                                     |
  711. ; | Groesser als Vergleich, DgtHs :  HL := DE  > HL vorzeichenbehaftet  |
  712. ; |                         DgtHu :  HL := DE  > HL vorzeichenlos       |
  713. ; |                                                                     |
  714. ; | TRUE -> HL=1, Z=0   FALSE -> HL=0, Z=1                              |
  715. ; |                                                                     |
  716. ; | A, DE benutzt.                                                      |
  717. ; |                                                                     |
  718. ; +---------------------------------------------------------------------+
  719.  
  720.           public DgtHs
  721.           public ?sgt
  722.           public DgtHu
  723.           public ?ugt
  724.  
  725. DgtHs:
  726. ?sgt:     ld    A,D             ; vorzeichenbehaftete Argumente in
  727.           xor   80h             ; fuer vorzeichenlosen Test 
  728.           ld    D,A             ; passende vorzeichenlose Argumente
  729.           ld    A,H             ; wandeln (s.o.)
  730.           xor   80h
  731.           ld    H,A
  732. DgtHu:
  733. ?ugt:     xor   A               ; vorzeichenloser Vergleich
  734.           sbc   HL,DE
  735.           ld    H,A
  736.           ld    L,A
  737.           jr    C,?true
  738.           xor   A
  739.           ret
  740.  
  741.  
  742.  
  743.  
  744.  
  745. ; +---------------------------------------------------------------------+
  746. ; |                                                                     |
  747. ; | Kleiner als Vergleich, DltHs :  HL := DE  < HL vorzeichenbehaftet   |
  748. ; |                        DltHu :  HL := DE  < HL vorzeichenlos        |
  749. ; |                                                                     |
  750. ; | TRUE -> HL=1, Z=0   FALSE -> HL=0, Z=1                              |
  751. ; |                                                                     |
  752. ; | A, DE benutzt.                                                      |
  753. ; |                                                                     |
  754. ; +---------------------------------------------------------------------+
  755.  
  756.           public DltHs
  757.           public ?slt
  758.           public DltHu
  759.           public ?ult
  760.  
  761. DltHs:
  762. ?slt:     ld    A,D             ; vorzeichenbehaftete Argumente in 
  763.           xor   80h             ; fuer vorzeichenlosen Test
  764.           ld    D,A             ; passende vorzeichenlose Argumente
  765.           ld    A,H             ; wandeln (s.o.)
  766.           xor   80h
  767.           ld    H,A
  768. DltHu:
  769. ?ult:     ex    DE,HL           ; vorzeichenloser Vergleich
  770.           xor   A
  771.           sbc   HL,DE
  772.           ld    H,A
  773.           ld    L,A
  774.           jr    C,?true
  775.           xor   A
  776.           ret
  777.  
  778.  
  779.  
  780.  
  781.  
  782. ; +---------------------------------------------------------------------+
  783. ; |                                                                     |
  784. ; | Kleiner gleich Vergleich, DleHs :  HL := DE <= HL vorzeichenbehaft. |
  785. ; |                           DleHu :  HL := DE <= HL vorzeichenlos     |
  786. ; |                                                                     |
  787. ; | TRUE -> HL=1, Z=0   FALSE -> HL=0, Z=1                              |
  788. ; |                                                                     |
  789. ; | A, DE benutzt.                                                      |
  790. ; |                                                                     |
  791. ; +---------------------------------------------------------------------+
  792.  
  793.           public DleHs
  794.           public ?sle
  795.           public DleHu
  796.           public ?ule
  797.  
  798. DleHs:
  799. ?sle:     ld    A,D             ; vorzeichenbehaftete Argumente in
  800.           xor   80h             ; fuer vorzeichenlosen Test
  801.           ld    D,A             ; passende vorzeichenlose Argumente
  802.           ld    A,H             ; wandeln (s.o.)
  803.           xor   80h
  804.           ld    H,A
  805. DleHu:
  806. ?ule:     xor   A               ; vorzeichenloser Vergleich
  807.           sbc   HL,DE
  808.           ld    H,A
  809.           ld    L,A
  810.           jr    NC,?true
  811.           xor   A
  812.           ret
  813.  
  814.  
  815.  
  816.  
  817.  
  818. ; +---------------------------------------------------------------------+
  819. ; |                                                                     |
  820. ; | Groesser gleich Vergleich, DgeHs :  HL := DE >= HL vorzeichenbeh.   |
  821. ; |                            DgeHu :  HL := DE >= HL vorzeichenlos    |
  822. ; |                                                                     |
  823. ; | TRUE -> HL=1, Z=0   FALSE -> HL=0, Z=1                              |
  824. ; |                                                                     |
  825. ; | A, DE benutzt.                                                      |
  826. ; |                                                                     |
  827. ; +---------------------------------------------------------------------+
  828.  
  829.           public DgeHs
  830.           public ?sge
  831.           public DgeHu
  832.           public ?uge
  833.  
  834. DgeHs:
  835. ?sge:     ld    A,D             ; vorzeichenbehaftete Argumente in
  836.           xor   80h             ; fuer vorzeichenlosen Test
  837.           ld    D,A             ; passende vorzeichenlose Argumente
  838.           ld    A,H             ; wandeln (s.o.)
  839.           xor   80h
  840.           ld    H,A
  841. DgeHu:
  842. ?uge:     ex    DE,HL           ; vorzeichenloser Vergleich
  843.           xor   A
  844.           sbc   HL,DE
  845.           ld    H,A
  846.           ld    L,A
  847.           jr    NC,?true
  848.           xor   A
  849.           ret
  850.  
  851.  
  852.  
  853.  
  854.  
  855. ; +---------------------------------------------------------------------+
  856. ; |                                                                     |
  857. ; | Arithmetischen Rechtsschieben, DsrHa :  HL := DE >> HL              |
  858. ; |                                HsrDa :  HL := HL >> DE              |
  859. ; |                                                                     |
  860. ; +---------------------------------------------------------------------+
  861.  
  862.           public DsrHa
  863.           public ?ssr
  864.           public HsrDa
  865.           public ?s1sr
  866.  
  867. DsrHa:
  868. ?ssr:     ex    DE,HL           ; HL <-> DE
  869. HsrDa:
  870. ?s1sr:    dec   E               ; alles geschoben (LSB-Abfrage reicht) ?
  871.           ret   M               ; ja   - dann war's das
  872.           sra   H               ; nein - HL arithmetisch rechtsschieben
  873.           rr    L               ;        um ein Bit,
  874.           jr    ?s1sr           ;        naechstes Bit
  875.  
  876.  
  877.  
  878.  
  879.  
  880. ; +---------------------------------------------------------------------+
  881. ; |                                                                     |
  882. ; | Logisches und arithmetisches Linksschieben, DslH :  HL := DE << HL  |
  883. ; |                                             HslD :  HL := HL << DE  |
  884. ; |                                                                     |
  885. ; +---------------------------------------------------------------------+
  886.  
  887.           public DslH
  888.           public ?ssl
  889.           public HslD
  890.           public ?s1sl
  891.  
  892. DslH:
  893. ?ssl:     ex    DE,HL           ; HL <-> DE
  894. HslD:  
  895. ?s1sl:    dec   E               ; alles geschoben (LSB-Abfrage reicht) ?
  896.           ret   M               ; ja   - dann war's das
  897.           add   HL,HL           ; nein - HL logisch/arithmetisch ein Bit
  898.           jr    ?s1sl           ;        linksschieben, naechstes Bit
  899.  
  900.  
  901.  
  902.  
  903.  
  904. ; +---------------------------------------------------------------------+
  905. ; |                                                                     |
  906. ; | Logisches Rechtsschieben, DsrHl :  HL := DE >> HL                   |
  907. ; |                           HsrDl :  HL := HL >> DE                   |
  908. ; |                                                                     |
  909. ; +---------------------------------------------------------------------+
  910.  
  911.           public DsrHl
  912.           public ?usr
  913.           public HsrDl
  914.           public ?u1sr
  915.  
  916. DsrHl:
  917. ?usr:     ex    DE,HL           ; HL <-> DE
  918. HsrDl:
  919. ?u1sr:    dec   E               ; alles geschoben (LSB Abfrage reicht) ?
  920.           ret   M               ; ja   - dann war's das
  921.           srl   H               ; nein - HL logisch rechtsschieben ein Bit
  922.           rr    L
  923.           jr    ?u1sr           ;        naechstes Bit
  924.  
  925.  
  926.  
  927.  
  928.  
  929. ; +---------------------------------------------------------------------+
  930. ; |                                                                     |
  931. ; | Subtraktion vorzeichenlos/vorzeichenbehaftet,                       |
  932. ; |                                                                     |
  933. ; |    DminH :  HL := DE - HL                                           |
  934. ; |    HminD :  HL := HL - DE                                           |
  935. ; |                                                                     |
  936. ; | A benutzt.                                                          |
  937. ; |                                                                     |
  938. ; +---------------------------------------------------------------------+
  939.  
  940.           public DminH
  941.           public ?ss
  942.           public HminD
  943.           public ?s1s
  944.  
  945. DminH:
  946. ?ss:      ex    DE,HL           ; DE <-> HL
  947. HminD:
  948. ?s1s:     xor   A               ; Carry loeschen
  949.           sbc   HL,DE           ; "DE" - "HL"
  950.           ret
  951.  
  952.  
  953.  
  954.  
  955.  
  956. ; +---------------------------------------------------------------------+
  957. ; |                                                                     |
  958. ; | Zweierkomplement, HL := -HL.                                        |
  959. ; |                                                                     |
  960. ; | A benutzt.                                                          |
  961. ; |                                                                     |
  962. ; +---------------------------------------------------------------------+
  963.  
  964.           public com2H
  965.           public ?sneg
  966.  
  967. com2H:
  968. ?sneg:    ld    A,H             ; HL bitweise invertieren
  969.           cpl
  970.           ld    H,A
  971.           ld    A,L
  972.           cpl
  973.           ld    L,A
  974.           inc   HL              ; und 1 dazu
  975.           ret
  976.  
  977.  
  978.  
  979.  
  980.  
  981. ; +---------------------------------------------------------------------+
  982. ; |                                                                     |
  983. ; | Einerkomplement, HL := ~HL.                                         |
  984. ; |                                                                     |
  985. ; | A benutzt.                                                          |
  986. ; |                                                                     |
  987. ; +---------------------------------------------------------------------+
  988.  
  989.           public com1H
  990.           public ?scom
  991.  
  992. com1H:
  993. ?scom:    ld    A,H             ; HL bitweise invertieren
  994.           cpl
  995.           ld    H,A
  996.           ld    A,L
  997.           cpl
  998.           ld    L,A
  999.           ret
  1000.  
  1001.  
  1002.  
  1003.  
  1004.  
  1005. ; +---------------------------------------------------------------------+
  1006. ; |                                                                     |
  1007. ; | Logisches Und invertiert, HL := !(DE & HL).                         |
  1008. ; |                                                                     |
  1009. ; | A benutzt.                                                          |
  1010. ; |                                                                     |
  1011. ; +---------------------------------------------------------------------+
  1012.  
  1013.           public nDandH
  1014.           public ?sna
  1015.  
  1016. nDandH:
  1017. ?sna:     call  ?sa            ; Logisches Und, dann !HL s.u.
  1018.  
  1019.  
  1020.  
  1021.  
  1022.  
  1023. ; +---------------------------------------------------------------------+
  1024. ; |                                                                     |
  1025. ; | (RST28) Logisches Nicht, HL := !HL.                                 |
  1026. ; |                                                                     |
  1027. ; | A benutzt.                                                          |
  1028. ; |                                                                     |
  1029. ; +---------------------------------------------------------------------+
  1030.  
  1031.           public nH
  1032.           public ?sn
  1033.  
  1034. nH:
  1035. ?sn:      ld    A,H             ; HL = 0, d.h. FALSE ?
  1036.           or    L
  1037.           jr    Z,?not1
  1038.           xor   A               ; nein -  Z = 1, d.h. FALSE
  1039.           ld    H,A             ;        HL = 0, d.h. FALSE
  1040.           ld    L,A
  1041.           ret                   ;        das war's = return(FALSE)
  1042. ?not1:    inc   L               ; ja   - HL = 1, Z = 0, d.h TRUE
  1043.           ret                   ;        das war's = return(TRUE)
  1044.  
  1045.  
  1046.  
  1047.  
  1048.  
  1049. ; +---------------------------------------------------------------------+
  1050. ; |                                                                     |
  1051. ; | Multiplikation, HL := DE * HL vorzeichenbehaftet/vorzeichenlos.     |
  1052. ; |                                                                     |
  1053. ; | A, DE benutzt.                                                      |
  1054. ; |                                                                     |
  1055. ; +---------------------------------------------------------------------+
  1056.  
  1057.           public DmulH
  1058.           public ?smult
  1059.           public ?umult
  1060.  
  1061. DmulH:
  1062. ?smult: 
  1063. ?umult:   ld    A,H             ; 8 bit * 16 bit oder 16 bit * 16 bit ?
  1064.           or    A
  1065.           ld    A,L             ; A LSB Multiplikand (beide Faelle)
  1066.           ld    L,H             ; L MSB Multiplikand (16 * 16)
  1067.                                 ; oder Ergebnisregister HL geloescht (8 * 16)
  1068.           jr    Z,?mult5        ; ->  8 * 16
  1069.           push  BC              ; -> 16 * 16, benutztes Register sichern
  1070.           ld    C,H             ; MSB Multiplikand sichern
  1071.           ld    HL,0            ; Resultatsregister loeschen
  1072.           ld    B,8             ; 8 Shifts/Additionen fuer LSB
  1073. ?mult1:   srl   A               ; shifte und
  1074.           jr    NC,?mult2       ; addiere, wenn Bit gesetzt
  1075.           add   HL,DE
  1076. ?mult2:   sla   E               ; shifte auch Multiplikator
  1077.           rl    D
  1078.           djnz  ?mult1          ; bis alle 8 Bit verarbeitet
  1079.           ld    A,C             ; MSB Multiplikand holen
  1080.           pop   BC              ; benutztes Register restaurieren
  1081.           jr    ?mult5          ; und nun MSB verarbeiten
  1082.   
  1083. ?mult3:   add   HL,DE           ; addiere wenn Bit gesetzt
  1084. ?mult4:   sla   E               ; shifte Multiplikator
  1085.           rl    D
  1086. ?mult5:   srl   A               ; shifte und
  1087.           jr    C,?mult3        ; addiere wenn Bit gesetzt
  1088.           jr    NZ,?mult4       ; fertig ? -> nein, naechstes Bit
  1089.           ret                   ;          -> ja, dann war's das
  1090.  
  1091.  
  1092.  
  1093.  
  1094.  
  1095. ; +---------------------------------------------------------------------+
  1096. ; |                                                                     |
  1097. ; | Division vorzeichenbehaftet,                                        |
  1098. ; |                                                                     |
  1099. ; |    DdivHs :  HL := DE / HL                                          |
  1100. ; |    HdivDs :  HL := HL / DE                                          |
  1101. ; |                                                                     |
  1102. ; | A benutzt.                                                          |
  1103. ; |                                                                     |
  1104. ; +---------------------------------------------------------------------+
  1105.  
  1106.           public HdivDs
  1107.           public ?s1div
  1108.           public DdivHs
  1109.           public ?sdiv
  1110.  
  1111. HdivDs:
  1112. ?s1div:   ex    DE,HL           ; DE <-> HL
  1113. DdivHs:
  1114. ?sdiv:    ld    A,H             ; Vorzeichen des Ergebnisses (Quotient)
  1115.           xor   D               ; berechnen
  1116.           push  AF              ; und merken
  1117.           ld    A,H             ; Divisor negativ ?
  1118.           or    A
  1119.           jp    P,?div1         ; nein -
  1120.           cpl                   ; ja   - positiv machen (2er-Komplement)
  1121.           ld    H,A
  1122.           ld    A,L
  1123.           cpl
  1124.           ld    L,A
  1125.           inc   HL
  1126. ?div1:    ld    A,D             ; Vorzeichen Dividend = Vorzeichen Rest
  1127.           or    A
  1128.           push  AF              ; merken
  1129.           jp    P,?div2         ; Dividend negativ ? -> nein -
  1130.           cpl                   ; -> ja   - positiv machen (2er-Komplement)
  1131.           ld    D,A
  1132.           ld    A,E
  1133.           cpl
  1134.           ld    E,A
  1135.           inc   DE
  1136. ?div2:    call  ?udiv           ; vorzeichenlose Division ausfuehren
  1137.           pop   AF              ; Rest negativ ?
  1138.           jp    P,?div3         ; nein -
  1139.           ld    A,D             ; ja   - negativ machen (2er-Komplement)
  1140.           cpl
  1141.           ld    D,A
  1142.           ld    A,E
  1143.           cpl
  1144.           ld    E,A
  1145.           inc   DE
  1146. ?div3:    pop   AF              ; Ergebnis (Quotient) negativ ?
  1147.           ret   P               ; nein - dann war's das
  1148.           ld    A,H             ; ja   - negativ machen (2er-Komplement)
  1149.           cpl
  1150.           ld    H,A
  1151.           ld    A,L
  1152.           cpl
  1153.           ld    L,A
  1154.           inc   HL
  1155.           ret                   ; das war's
  1156.  
  1157.  
  1158.  
  1159.  
  1160.  
  1161. ; +---------------------------------------------------------------------+
  1162. ; |                                                                     |
  1163. ; | Division vorzeichenlos,                                             |
  1164. ; |                                                                     |
  1165. ; |    DdivHu :  HL := DE / HL                                          |
  1166. ; |    HdivDu :  HL := HL / DE                                          |
  1167. ; |                                                                     |
  1168. ; | A benutzt.                                                          |
  1169. ; |                                                                     |
  1170. ; +---------------------------------------------------------------------+
  1171.  
  1172.           public HdivDu
  1173.           public ?u1div
  1174.           public DdivHu
  1175.           public ?udiv
  1176.  
  1177. HdivDu:
  1178. ?u1div:   ex    DE,HL           ; DE <-> HL
  1179. DdivHu:
  1180. ?udiv:    ld    A,H             ; Division durch 0 ?
  1181.           or    L
  1182.           jr    NZ,?udiv0
  1183.           ld    E,L             ; ja   - Ergebnis und Rest 0
  1184.           ld    D,H
  1185.           ret
  1186.  
  1187. ?udiv0:   push  BC              ; nein - benutztes Register sichern
  1188.           ld    B,H             ; Divisor in BC
  1189.           ld    C,L
  1190.           ld    HL,0            ; Ergebnis (Quotient) loeschen
  1191.           ld    A,16            ; 16 Bit muessen berechnet werden
  1192.           ex    DE,HL           ; HL = Dividend
  1193. ?udiv1:   add   HL,HL           ; Dividend normieren
  1194.           jr    C,?udiv3        ; (linksschieben bis zum Anschlag + 1)
  1195.           dec   A
  1196.           jr    NZ,?udiv1       ; Dividend 0 ? nein - naechstes Bit
  1197.           pop   BC              ; ja   - benutztes Register restaurieren
  1198.           ret                   ;        das war's dann schon hier
  1199.  
  1200. ?udiv2:   ex    DE,HL           ; Ergebnis (Quotient) naechste Stelle
  1201.           add   HL,HL
  1202. ?udiv3:   ex    DE,HL           ; Dividend naechste Stelle
  1203.           adc   HL,HL
  1204.           sbc   HL,BC           ; Dividend - Divisor >= 0 ?
  1205.           jr    NC,?udiv5       ; ja   - Ergebnis + 1, naechstes Bit
  1206.           add   HL,BC           ; nein - Dividend restaurieren
  1207. ?udiv4:   dec   A               ; Bitzaehler
  1208.           jr    NZ,?udiv2       ; fertig ? nein - naechstes Bit
  1209.           ex    DE,HL           ;          ja   - HL Quotient, DE Rest
  1210.           pop   BC              ;                 benutztes Reg. restaurieren
  1211.           ret                   ;                 das war's
  1212. ?udiv5:   inc   DE              ; Ergebnis (Quotient) + 1 und
  1213.           jr    ?udiv4          ; weiter zum naechsten Bit
  1214.  
  1215.  
  1216.  
  1217.  
  1218.  
  1219. ; +---------------------------------------------------------------------+
  1220. ; |                                                                     |
  1221. ; | Rest vorzeichenbehaftet,                                            |
  1222. ; |                                                                     |
  1223. ; |    DmodHs :  HL := DE % HL                                          |
  1224. ; |    HmodDs :  HL := HL % DE                                          |
  1225. ; |                                                                     |
  1226. ; | A benutzt.                                                          |
  1227. ; |                                                                     |
  1228. ; +---------------------------------------------------------------------+
  1229.  
  1230.           public HmodDs
  1231.           public ?s1rem
  1232.           public DmodHs
  1233.           public ?srem
  1234.  
  1235. HmodDs:
  1236. ?s1rem:   ex    DE,HL           ; DE <-> HL
  1237. DmodHs:
  1238. ?srem:    call  ?sdiv           ; Division ausfuehren
  1239.           ex    DE,HL           ; Rest ist Ergebnis
  1240.           ret
  1241.  
  1242.  
  1243.  
  1244.  
  1245.  
  1246. ; +---------------------------------------------------------------------+
  1247. ; |                                                                     |
  1248. ; | Rest vorzeichenlos,                                                 |
  1249. ; |                                                                     |
  1250. ; |    DmodHu :  HL := DE % HL                                          |
  1251. ; |    HmodDu :  HL := HL % DE                                          |
  1252. ; |                                                                     |
  1253. ; | A benutzt.                                                          |
  1254. ; |                                                                     |
  1255. ; +---------------------------------------------------------------------+
  1256.  
  1257.           public HmodDu
  1258.           public ?u1rem
  1259.           public DmodHu
  1260.           public ?urem
  1261.  
  1262. HmodDu:
  1263. ?u1rem:   ex    DE,HL           ; DE <-> HL
  1264. DmodHu:
  1265. ?urem:    call  ?udiv           ; Division ausfuehren
  1266.           ex    DE,HL           ; Rest ist Ergebnis
  1267.           ret
  1268.  
  1269.  
  1270.  
  1271.  
  1272.  
  1273. ; +---------------------------------------------------------------------+
  1274. ; |                                                                     |
  1275. ; | switch-Anwahl, HL enthaelt zu testenden Wert, Tabelle als Parameter |
  1276. ; | hinter Aufruf :                                                     |
  1277. ; |                                                                     |
  1278. ; |   16 Bit Anzahl Faelle ohne default       ( < 256 ! )               |
  1279. ; |   je Fall :  16 Bit Fall-Wert                                       |
  1280. ; |              16 Bit Adresse des Falls                               |
  1281. ; |              .                                                      |
  1282. ; |              .                                                      |
  1283. ; |   16 Bit Adresse default Bearbeitung                                |
  1284. ; |                                                                     |
  1285. ; | A, HL, DE benutzt.                                                  |
  1286. ; |                                                                     |
  1287. ; +---------------------------------------------------------------------+
  1288.  
  1289.           public switch
  1290.           public ?sw
  1291.  
  1292. switch:
  1293. ?sw:      ex    DE,HL           ; switch-Wert sichern
  1294.           pop   HL              ; Adresse der Argumentenliste
  1295.           push  BC              ; Stackframe-Pointer sichern
  1296.           ld    C,(HL)          ; Anzahl der Faelle
  1297.           inc   HL              ; (immer < 256, MSB ignorieren)
  1298. ?sw1:     dec   C               ; Faelle herunterzaehlen
  1299.           jp    M,?sw3          ; keine weiteren Faelle - default ausfuehren
  1300.           inc   HL              ; Fall gefunden (Werte gleich) ?
  1301.           ld    A,(HL)          ; LSB ...
  1302.           cp    E
  1303.           inc   HL
  1304.           jr    NZ,?sw2         ; nein - naechster Fall
  1305.           ld    A,(HL)          ; MSB ...
  1306.           cp    D
  1307.           jr    Z,?sw3          ; ja   - zugehoerige Routine ausfuehren
  1308. ?sw2:     inc   HL              ; nein - zum naechsten Falleintrag
  1309.           inc   HL
  1310.           jr    ?sw1            ; diesen probieren
  1311.  
  1312. ?sw3:     inc   HL              ; Adresse des gewaehlten Falls holen
  1313.           ld    A,(HL)          ; LSB ...
  1314.           inc   HL
  1315.           ld    H,(HL)          ; MSB ...
  1316.           ld    L,A
  1317.           pop   BC              ; Stackframe-Pointer restaurieren
  1318.           jp    (HL)            ; und Routine ausfuehren
  1319.  
  1320.  
  1321.  
  1322.  
  1323.  
  1324. ; +---------------------------------------------------------------------+
  1325. ; |                                                                     |
  1326. ; | Funktionsstart fuer Parameter, es werden die Stackframepointer      |
  1327. ; | (BC/IX) gesetzt, so dass auf Funktionsargumente zugegriffen werden  |
  1328. ; | kann.                                                               |
  1329. ; |                                                                     |
  1330. ; | Return :  HL  -  benutzt                                            |
  1331. ; |                                                                     |
  1332. ; +---------------------------------------------------------------------+
  1333.  
  1334.           public fentp
  1335.           public ?en
  1336.  
  1337. fentp:
  1338. ?en:      pop   HL              ; Returnadresse holen
  1339.           push  BC              ; Stackframe-Pointer sichern
  1340.           ld    IX,0            ; lokaler Stackframe-Pointer, kein Platz
  1341.           add   IX,SP           ; fuer lokale Variablen benoetigt
  1342.           push  IX              ; BC auch Stackframe-Pointer
  1343.           pop   BC
  1344.           jp    (HL)            ; das war's - weiter an Returnadresse
  1345.  
  1346.  
  1347.  
  1348.  
  1349.  
  1350. ; +---------------------------------------------------------------------+
  1351. ; |                                                                     |
  1352. ; | Funktionsstart fuer Parameter/Locals, wie fentp, zusaetzlich wird   |
  1353. ; | Platz fuer lokale Variable auf dem Stack geschaffen, Platz in Bytes |
  1354. ; | negativ als Parameter hinter Aufruf (16 Bit).                       |
  1355. ; |                                                                     |
  1356. ; | Return :  SP      -  um angeforderten Platz korrigiert              |
  1357. ; |           BC, IX  -  neuer Stackframe-Pointer                       |
  1358. ; |           DE, HL  -  benutzt                                        |
  1359. ; |                                                                     |
  1360. ; |                                                                     |
  1361. ; +---------------------------------------------------------------------+
  1362.  
  1363.           public fentpl
  1364.           public ?ens
  1365.  
  1366. fentpl:
  1367. ?ens:     pop   HL              ; Adresse Aufrufpar. (angeforderter Platz)
  1368.           push  BC              ; Stackframe-Pointer sichern
  1369.           ld    E,(HL)          ; LSB angeforderter Platz 
  1370.           inc   HL              ; Zeiger auf MSB angeforderter Platz
  1371.           ld    D,(HL)          ; MSB angeforderter Platz
  1372.           inc   HL              ; neue Returnadresse hinter Parameter
  1373.           ex    DE,HL           ; Returnadresse <-> angeforderter Platz
  1374.           add   HL,SP           ; Stack um angeforderten Platz vermindern
  1375.           ld    SP,HL           ; und den Platz reservieren
  1376.           ld    B,H             ; lokalen Stackframe-Pointer setzen
  1377.           ld    C,L
  1378.           push  BC              ; auch in IX
  1379.           pop   IX
  1380.           ex    DE,HL           ; HL = Returnadresse
  1381.           jp    (HL)            ; das war's - dort weitermachen
  1382.  
  1383.  
  1384.  
  1385.  
  1386.  
  1387. ; +---------------------------------------------------------------------+
  1388. ; |                                                                     |
  1389. ; | Funktionsausgang fuer Parameter/Locals, nach fentpl, der lokal      |
  1390. ; | benoetigte Platz wird zurueckgegeben, Platz in Bytes positiv als    |
  1391. ; | Parameter hinter Aufruf (16 Bit).                                   |
  1392. ; |                                                                     |
  1393. ; | Return :  SP      -  um zurueckzugebenden Platz korrigiert          |
  1394. ; |           BC, IX  -  alter Stackframe-Pointer (aufrufende Funktion) |
  1395. ; |           HL      -  bleibt (Returnwert der Funktion)               |
  1396. ; |           A, DE   -  benutzt                                        |
  1397. ; |                                                                     |
  1398. ; +---------------------------------------------------------------------+
  1399.  
  1400.           public fextpl
  1401.           public ?exs
  1402.  
  1403. fextpl:
  1404. ?exs:     ex    DE,HL           ; Returnwert der Funktion sichern
  1405.           pop   HL              ; Adresse Aufrufparam. (zurueckzugeb. Platz)
  1406.           ld    A,(HL)          ; LSB des zurueckzugebenden Platzes holen
  1407.           inc   HL              ; Zeiger auf MSB
  1408.           ld    H,(HL)          ; MSB holen 
  1409.           ld    L,A             ; HL = 16-Bit Anzahl Bytes zureckzugeben
  1410.           add   HL,SP           ; = Anzahl Bytes Stack zu korrigieren
  1411.           ld    SP,HL           ; lokalen Platz deallokieren
  1412.           ex    DE,HL           ; restaurieren des Returnwertes der Funktion
  1413.           pop   BC              ; Stackframe-Pointer restaurieren
  1414.           push  BC
  1415.           pop   IX              ; sowie Indexregister (auch Stackframe-P.)
  1416.           ret                   ; das war's
  1417.  
  1418.  
  1419.  
  1420.  
  1421.  
  1422. ; +---------------------------------------------------------------------+
  1423. ; |                                                                     |
  1424. ; | Definitionen zum Zusammenspiel mit dem Compiler.                    |
  1425. ; |                                                                     |
  1426. ; | Bei Benutzung des originalen Compilers werden alle Routinen des     |
  1427. ; | Runtime-Moduls immer als extern deklariert, auch wenn sie nicht     |
  1428. ; | benutzt werden. Bei Benutzung eines anderen Runtime-Moduls mit      |
  1429. ; | weniger Routinen muessen die fehlenden Routinen also zumindest      |
  1430. ; | definiert werden.                                                   |
  1431. ; |                                                                     |
  1432. ; +---------------------------------------------------------------------+
  1433.  
  1434.           public ?enr
  1435.           public ?ensr
  1436.           public ?exr
  1437.           public ?exrs
  1438.           public r?1?
  1439.           public r?2?
  1440.           public r?3?
  1441.           public r?4?
  1442.           public r?5?
  1443.  
  1444. ?enr      equ   0
  1445. ?ensr     equ   0
  1446. ?exr      equ   0
  1447. ?exrs     equ   0
  1448. r?1?      equ   0
  1449. r?2?      equ   0
  1450. r?3?      equ   0
  1451. r?4?      equ   0
  1452. r?5?      equ   0
  1453.  
  1454.  
  1455.  
  1456.  
  1457.  
  1458. ; +---------------------------------------------------------------------+
  1459. ; |                                                                     |
  1460. ; | Wenn CRUNTIME als letztes Modul gebunden wird, hat end im Programm- |
  1461. ; | lauf die Adresse hinter dem letzten Codebyte.                       |
  1462. ; |                                                                     |
  1463. ; +---------------------------------------------------------------------+
  1464.  
  1465.           public end?
  1466.  
  1467. end?:
  1468.  
  1469.  
  1470.  
  1471.           end
  1472.                                             
  1473.